package com.demo.cn.greendaodemo;

import android.app.Application;
import android.database.sqlite.SQLiteDatabase;

import com.demo.cn.greendaodemo.entity.DaoMaster;
import com.demo.cn.greendaodemo.entity.DaoSession;

/**
 * Created by admin at 2018/11/1
 */

public class MyApplication extends Application {
    private DaoMaster.DevOpenHelper mHelper;
    private SQLiteDatabase db;
    private DaoMaster mDaoMaster;
    private DaoSession mDaoSession;
    public static MyApplication instances;

    @Override
    public void onCreate() {
        super.onCreate();
        instances = this;
        setDatabase();
    }


    /**
     * 单例模式 * *
     */
    public static MyApplication getInstances() {
        return instances;
    }
    private void setDatabase() {
        mHelper = new DaoMaster.DevOpenHelper(this, "user-db", null);
        db = mHelper.getWritableDatabase();  mDaoMaster = new DaoMaster(db);
        mDaoSession = mDaoMaster.newSession();

    }
    public DaoSession getDaoSession() {
        return mDaoSession;
    }

    public SQLiteDatabase getDb() {
        return db;
    }
}
